<!doctype html>
<html class="theme-next use-motion theme-next-mist">
<head>
  
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

  <meta name="google-site-verification" content="K8DCBviaoTBKVs28YBB7IBIbospQ9RVlgSh81RYMUhY" />


  <meta name="baidu-site-verification" content="tXr3ZTm3Hx" />



  <link rel="stylesheet" type="text/css" href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5"/>


<link rel="stylesheet" type="text/css" href="/css/main.css?v=0.4.5.1"/>

  <meta name="description" content="xgfe's blog. 鲜果前端的技术博客，鲜果前端研发部官方博客。前端基础技术研究：html, html5, javascript, css, css3；前端框架研究：angularJs, react, react native." />


  <meta name="keywords" content="svg,进阶," />


  <link rel="alternate" target="_blank" href="/atom.xml" title="xgfe" type="application/atom+xml" />


  <link rel="shorticon icon" type="image/x-icon" href="http://p0.meituan.net/xgfe/2db359f56ce13be30dedef160e0e57ce16958.ico?v=0.4.5.1" />

<meta name="description" content="本文在大概了解SVG的基础上，深入的讲解一些SVG常用的知识，主要有以下几点    JS操作SVG viewport和viewbox SVG变换 SVG动画 SVG clip-path">
<meta name="keywords" content="svg,进阶">
<meta property="og:type" content="article">
<meta property="og:title" content="SVG进阶教程">
<meta property="og:url" content="http://xgfe.github.io/2015/11/17/scliuyang/svg-advanced/index.html">
<meta property="og:site_name" content="xgfe">
<meta property="og:description" content="本文在大概了解SVG的基础上，深入的讲解一些SVG常用的知识，主要有以下几点    JS操作SVG viewport和viewbox SVG变换 SVG动画 SVG clip-path">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-1.png">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-2.png">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-3.png">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-5.png">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-6.jpg">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-7.jpg">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-8.png">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-9.png">
<meta property="og:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-10.png">
<meta property="og:updated_time" content="2017-04-12T08:03:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="SVG进阶教程">
<meta name="twitter:description" content="本文在大概了解SVG的基础上，深入的讲解一些SVG常用的知识，主要有以下几点    JS操作SVG viewport和viewbox SVG变换 SVG动画 SVG clip-path">
<meta name="twitter:image" content="http://xgfe.github.io/uploads/scliuyang/svg-advance/svg-1.png">


<script type="text/javascript" id="hexo.configuration">
  var CONFIG = {
    scheme: 'Mist',
    sidebar: 'post'
  };
</script>

  <title> SVG进阶教程 | xgfe </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
  <div style="position: fixed; top: -9999px; left: -9999px;">
    <img src="http://p0.meituan.net/xgfe/082a9624ba5ae8602150a2d43968463e49348.png" alt="xgfe"/>
  </div>
  <!--[if lte IE 8]>
  <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;margin:0 auto;'>
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
      <img src="http://7u2nvr.com1.z0.glb.clouddn.com/picouterie.jpg" border="0" height="42" width="820"
           alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today or use other browser ,like chrome firefox safari."
           style='margin-left:auto;margin-right:auto;display: block;'/>
    </a>
  </div>
<![endif]-->
  

  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?3601d4483819a5ab6ddabb0b6422a328";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>



  <div class="container one-column page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><h1 class="site-meta">
  <span class="logo-line-before"><i></i></span>
  <a href="/" class="brand" rel="start">
      <span class="logo">
        <i class="icon-next-logo"></i>
      </span>
      <span class="site-title">xgfe</span>
  </a>
  <span class="logo-line-after"><i></i></span>
</h1>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  
  

  
    <ul id="menu" class="menu menu-left">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon icon-next-home"></i> <br />
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            <i class="menu-item-icon icon-next-archives"></i> <br />
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            <i class="menu-item-icon icon-next-tags"></i> <br />
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-join">
          <a href="/join" rel="section">
            <i class="menu-item-icon icon-next-join"></i> <br />
            加入我们
          </a>
        </li>
      
      <!-- slide-links added by felix -->
      <li class="menu-item menu-item-slides" style="opacity: 1; transform: translateY(0px);">
        <a href="http://xgfe.github.io/Basics/" target="_blank" rel="section">
          <i class="menu-item-icon icon-next-slides"></i> <br>
          Basics
        </a>
      </li>
      <li class="menu-item menu-item-slides" style="opacity: 1; transform: translateY(0px);">
        <a href="https://slides.com/xgfe" target="_blank" rel="section">
          <i class="menu-item-icon icon-next-slides"></i> <br>
          Slides
        </a>
      </li>

      
      
    </ul>
  

  
    <div class="site-search">
      

    </div>
  

    <div class="site-search">
      <form class="site-search-form" id="gg-form" action="https://www.google.com/webhp" >
        <input type="text" name="q" id="gg-search-input" class="menu-search-input">
      </form>
    </div>
</nav>
 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div id="content" class="content"> 

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">

      
      
        <h1 class="post-title" itemprop="name headline">
          
          
            
              SVG进阶教程
            
          
        </h1>
      

      <div class="post-meta">
        <span class="post-time">
          发表于
          <time itemprop="dateCreated" datetime="2015-11-17T16:32:00+08:00" content="2015-11-17">
            2015-11-17
          </time>
        </span>

        
          <span class="post-category" >
            &nbsp; | &nbsp; 作者
            
              <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                <a href="/categories/scliuyang/" itemprop="url" rel="index">
                  <span itemprop="name">scliuyang</span>
                </a>
              </span>

              
              

            
          </span>
        

        
          
        

        <!-- tags 挪动位置 -->
        
          <span class="post-tags">
            &nbsp; | &nbsp;
            
              <a href="/tags/svg/" rel="tag"><i class="icon-next-tags"></i>svg</a>
            
              <a href="/tags/进阶/" rel="tag"><i class="icon-next-tags"></i>进阶</a>
            
          </span>
        
      </div>
    </header>

    <div class="post-body">

      
      

      
        <span itemprop="articleBody"><p>本文在大概了解SVG的基础上，深入的讲解一些SVG常用的知识，主要有以下几点  </p>
<ol>
<li>JS操作SVG</li>
<li>viewport和viewbox</li>
<li>SVG变换</li>
<li>SVG动画</li>
<li>SVG clip-path</li>
</ol>
<a id="more"></a>
<h1 id="JS如何操作SVG元素"><a href="#JS如何操作SVG元素" class="headerlink" title="JS如何操作SVG元素"></a>JS如何操作SVG元素</h1><p>创建SVG元素和普通创建DOM元素有细小的区别，创建SVG需要用到命名空间创建,举个栗子  </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">var svgNS = “http://www.w3.org/2000/svg”; //命名空间字符串</div><div class="line">var svgDom = document.createElementNS(svgNS, ‘svg’);</div></pre></td></tr></table></figure>
<p>当然对普通属性的操作使用setAttribue即可，但是如果操作SVG特有的属性即xlink:href之类的则必须使用如下的方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&lt;use xlink:href=&quot;#pat&quot;&gt; //操作xlink:href</div><div class="line"></div><div class="line">var xlinkNS = &quot;http://www.w3.org/1999/xlink&quot;;</div><div class="line">var use = document.createElementNS(svgNS, &apos;use&apos;);</div><div class="line">use.setAttributeNS(xlinkNS,&apos;href&apos;, &apos;#pat&apos;);</div></pre></td></tr></table></figure>
<h1 id="viewport和viewbox"><a href="#viewport和viewbox" class="headerlink" title="viewport和viewbox"></a>viewport和viewbox</h1><h2 id="viewport"><a href="#viewport" class="headerlink" title="viewport"></a>viewport</h2><p>首先呢讲解viewport之前，大家得先记着这个概念：我们的画布是无限大的。接着我们在来看看svg元素上的width和height，我们可以把SVG看做浏览器窗口（body部分）,width和height即浏览器的可视窗口大小，我们透过宽为width、高为height的矩形去看这块画布，画布超出部分自然也就看不到了,这个矩形呢就是viewport。</p>
<h2 id="viewbox"><a href="#viewbox" class="headerlink" title="viewbox"></a>viewbox</h2><p>假如我们想看超出部分怎么办呢？别着急，这时候就是viewbox排上用场的时候了。我们先来看看语法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">viewbox:x y width height</div></pre></td></tr></table></figure>
<p>x,y呢决定viewbox的左上角起始点(允许负值)，width,height决定viewbox的宽高。注意这里的宽高不一定要和SVG的宽高一致。设置viewbox的宽高例子如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;!-- viewbox和svg的宽高默认相等，可以设置不等值 --&gt;</div><div class="line">&lt;svg width=&quot;800&quot; height=&quot;600&quot; viewBox=&quot;0 0 800 600&quot;&gt; </div><div class="line">&lt;/svg&gt;</div></pre></td></tr></table></figure>
<p>现在我们有一个宽高都是500的SVG，里面有一个鹦鹉，如图<br><img src="/uploads/scliuyang/svg-advance/svg-1.png" style="width:200px;height:200px;"><br>我们设置viewbox=”0 0 100 100”,结果如下<br><img src="/uploads/scliuyang/svg-advance/svg-2.png" style="width:200px;height:200px;"><br><img src="/uploads/scliuyang/svg-advance/svg-3.png" style="width:200px;height:200px;"><br>可以清楚的看到浏览器将蓝色方框内的内容等比例拉伸到500，500的大小</p>
<p>现在是viewbox的宽高比和viewport的宽高比一致，当宽高比不一致的时候就需要用到</p>
<h2 id="preserveAspectRatio"><a href="#preserveAspectRatio" class="headerlink" title="preserveAspectRatio"></a>preserveAspectRatio</h2><p>preserveAspectRatio属性。我们先来看看preserveAspectRatio的语法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">preserveAspectRatio=&quot;align meetOrSlice&quot;</div></pre></td></tr></table></figure>
<h3 id="align"><a href="#align" class="headerlink" title="align"></a>align</h3><p>align取值为none时，宽高比不相同的话会强制拉伸充满整个viewport,就像这样<br><img src="/uploads/scliuyang/svg-advance/svg-5.png" style="height:200px;"></p>
<p>align的其他取值情况是下面两列的混合情况</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">xMin YMin</div><div class="line">xMid YMid</div><div class="line">xMax YMax</div></pre></td></tr></table></figure>
<p><img src="/uploads/scliuyang/svg-advance/svg-6.jpg"><br><img src="/uploads/scliuyang/svg-advance/svg-7.jpg"></p>
<h3 id="meetOrSlice"><a href="#meetOrSlice" class="headerlink" title="meetOrSlice"></a>meetOrSlice</h3><h4 id="meet-默认值）"><a href="#meet-默认值）" class="headerlink" title="meet(默认值）"></a>meet(默认值）</h4><p>基于以下两条准侧尽可能缩放元素： </p>
<ul>
<li>保持宽高比</li>
<li>整个viewBox在视窗中可见  </li>
</ul>
<p>在这个情况下，如果图形的宽高比不符合视窗，一些视窗会超出viewBox的边界（即viewBox绘制的区域会小于视窗）。（在viewBox一节查看最后的例子。）在这个情况下，viewBox的边界被包含在viewport中使得边界满足。</p>
<p>这个值类似于background-size: contain。背景图片在保持宽高比的情况下尽可能缩放并确保它适合背景绘制区域。如果背景的长宽比和应用的元素的长宽比不一样，部分背景绘制区域会没有背景图片覆盖。</p>
<h4 id="slice"><a href="#slice" class="headerlink" title="slice"></a>slice</h4><p>在保持宽高比的情况下，缩放图形直到viewBox覆盖了整个视窗区域。viewBox被缩放到正好覆盖视窗区域（在两个维度上），但是它不会缩放任何超出这个范围的部分。换而言之，它缩放到viewBox的宽高可以正好完全覆盖视窗。</p>
<p>在这种情况下，如果viewBox的宽高比不适合视窗，一部分viewBox会扩展超过视窗边界（即，viewBox绘制的区域会比视窗大）。这会导致部分viewBox被切片。</p>
<p>你可以把这个类比为background-size: cover。在背景图片的情况中，图片在保持本身宽高比（如何）的情况下缩放到宽高可以完全覆盖背景定位区域的最小尺寸。</p>
<p><a href="http://sarasoueidan.com/demos/interactive-svg-coordinate-system/index.html" target="_blank" rel="external">鹦鹉在线demo</a></p>
<h1 id="SVG变换"><a href="#SVG变换" class="headerlink" title="SVG变换"></a>SVG变换</h1><p>SVG元素也可以应用css变换，不过唯一需要注意的一点就是，svg元素的transform-origin是左上角0,0点,如果想像普通元素一样请设置transform-origin:50% 50%;<br><img src="/uploads/scliuyang/svg-advance/svg-8.png"></p>
<h1 id="SVG动画"><a href="#SVG动画" class="headerlink" title="SVG动画"></a>SVG动画</h1><p>SVG动画可以有3种实现方法  </p>
<ul>
<li>JS动画，利用requestAnimationFrame手动控制每一帧动画，缺点性能消耗大，不推荐</li>
<li>SMIL Synchronized Multimedia Integration Language(同步多媒体集成语言),最初的SVG动画方法，但是由于标准的变更，此方法将逐渐被CSS动画取代</li>
<li>CSS3动画，由于大部分SVG属性都可以使用css设置，故可以使用CSS动画，推荐</li>
</ul>
<p>参考链接：<br><a href="http://www.webhek.com/animated-line-drawing-in-svg" target="_blank" rel="external">帅气的描边动画</a><br><a href="http://www.oxxostudio.tw/articles/201407/svg-progress-bar.html" target="_blank" rel="external">很有创意的loading动画</a></p>
<h1 id="SVG-clip-path"><a href="#SVG-clip-path" class="headerlink" title="SVG clip-path"></a>SVG clip-path</h1><p>SVG剪切，配合defs使用，剪切定义路径以外的图像（隐藏）<br><img src="/uploads/scliuyang/svg-advance/svg-9.png"><br><img src="/uploads/scliuyang/svg-advance/svg-10.png"><br><a href="http://jsbin.com/kigiqidoze/edit?html,js,output" target="_blank" rel="external">亲自试一试</a></p>
</span>
      
    </div>

    <footer class="post-footer">

      
        <div class="post-nav">
          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/11/23/chenwubai/d3-basicCharts-bar/" rel="prev">基于D3.js的柱状图的实现</a>
            
          </div>

          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/10/28/felix/git-commit-hook/" rel="next">git commit hook</a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>

 </div>

        

        
          <div class="comments" id="comments">
            <div id="SOHUCS" sid="" ></div>
          </div>
        
      </div>

      
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <a href="https://github.com/xgfe" target="_blank"><img class="site-author-image" src="http://p0.meituan.net/xgfe/082a9624ba5ae8602150a2d43968463e49348.png" alt="xgfe" itemprop="image"/></a>
          <p class="site-author-name" itemprop="name">xgfe</p>
        </div>
        <p class="site-description motion-element" itemprop="description">xgfe's blog. 鲜果前端的技术博客，鲜果前端研发部官方博客。前端基础技术研究：html, html5, javascript, css, css3；前端框架研究：angularJs, react, react native.</p>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">89</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          <div class="site-state-item site-state-categories">
            
              <span class="site-state-item-count">37</span>
              <span class="site-state-item-name">作者</span>
              
          </div>

          <div class="site-state-item site-state-tags">
            <a href="/tags">
              <span class="site-state-item-count">131</span>
              <span class="site-state-item-name">标签</span>
              </a>
          </div>

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" target="_blank" rel="alternate">
              <i class="menu-item-icon icon-next-feed"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/xgfe" target="_blank">GitHub</a>
              </span>
            
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      
        <section class="post-toc-wrap sidebar-panel-active">
          <div class="post-toc-indicator-top post-toc-indicator"></div>
          <div class="post-toc">
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#JS如何操作SVG元素"><span class="nav-number">1.</span> <span class="nav-text">JS如何操作SVG元素</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#viewport和viewbox"><span class="nav-number">2.</span> <span class="nav-text">viewport和viewbox</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#viewport"><span class="nav-number">2.1.</span> <span class="nav-text">viewport</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#viewbox"><span class="nav-number">2.2.</span> <span class="nav-text">viewbox</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#preserveAspectRatio"><span class="nav-number">2.3.</span> <span class="nav-text">preserveAspectRatio</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#align"><span class="nav-number">2.3.1.</span> <span class="nav-text">align</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#meetOrSlice"><span class="nav-number">2.3.2.</span> <span class="nav-text">meetOrSlice</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#meet-默认值）"><span class="nav-number">2.3.2.1.</span> <span class="nav-text">meet(默认值）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#slice"><span class="nav-number">2.3.2.2.</span> <span class="nav-text">slice</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SVG变换"><span class="nav-number">3.</span> <span class="nav-text">SVG变换</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SVG动画"><span class="nav-number">4.</span> <span class="nav-text">SVG动画</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#SVG-clip-path"><span class="nav-number">5.</span> <span class="nav-text">SVG clip-path</span></a></li></ol></div>
            
          </div>
          <div class="post-toc-indicator-bottom post-toc-indicator"></div>
        </section>
      

    </div>
  </aside>


    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner"> <div class="copyright" >
  
  &copy; &nbsp; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="icon-next-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xgfe</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" target="_blank" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


 </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  
  
    <script type="text/javascript"> 
(function(){ 
var appid = 'cysWiXvkm'; 
var conf = 'prod_fc970dbe85103c7a79b2c4f3dc7fb190'; 
var width = window.innerWidth || document.documentElement.clientWidth; 
if (width < 960) { 
window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("http://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); </script>
    

  


  
  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>
  <script type="text/javascript" src="/js/fancy-box.js?v=0.4.5.1"></script>


  <script type="text/javascript" src="/js/helpers.js?v=0.4.5.1"></script>
  

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/js/motion_global.js?v=0.4.5.1" id="motion.global"></script>




  <script type="text/javascript" src="/js/nav-toggle.js?v=0.4.5.1"></script>
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  
<script type="text/javascript" src="/js/bootstrap.scrollspy.js?v=0.4.5.1" id="bootstrap.scrollspy.custom"></script>


<script type="text/javascript" id="sidebar.toc.highlight">
  $(document).ready(function () {
    var tocSelector = '.post-toc';
    var $tocSelector = $(tocSelector);
    var activeCurrentSelector = '.active-current';

    $tocSelector
      .on('activate.bs.scrollspy', function () {
        var $currentActiveElement = $(tocSelector + ' .active').last();

        removeCurrentActiveClass();
        $currentActiveElement.addClass('active-current');

        $tocSelector[0].scrollTop = $currentActiveElement.position().top;
      })
      .on('clear.bs.scrollspy', function () {
        removeCurrentActiveClass();
      });

    function removeCurrentActiveClass () {
      $(tocSelector + ' ' + activeCurrentSelector)
        .removeClass(activeCurrentSelector.substring(1));
    }

    function processTOC () {
      getTOCMaxHeight();
      toggleTOCOverflowIndicators();
    }

    function getTOCMaxHeight () {
      var height = $('.sidebar').height() -
                   $tocSelector.position().top -
                   $('.post-toc-indicator-bottom').height();

      $tocSelector.css('height', height);

      return height;
    }

    function toggleTOCOverflowIndicators () {
      tocOverflowIndicator(
        '.post-toc-indicator-top',
        $tocSelector.scrollTop() > 0 ? 'show' : 'hide'
      );

      tocOverflowIndicator(
        '.post-toc-indicator-bottom',
        $tocSelector.scrollTop() >= $tocSelector.find('ol').height() - $tocSelector.height() ? 'hide' : 'show'
      )
    }

    $(document).on('sidebar.motion.complete', function () {
      processTOC();
    });

    $('body').scrollspy({ target: tocSelector });
    $(window).on('resize', function () {
      if ( $('.sidebar').hasClass('sidebar-active') ) {
        processTOC();
      }
    });

    onScroll($tocSelector);

    function onScroll (element) {
      element.on('mousewheel DOMMouseScroll', function (event) {
          var oe = event.originalEvent;
          var delta = oe.wheelDelta || -oe.detail;

          this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
          event.preventDefault();

          toggleTOCOverflowIndicators();
      });
    }

    function tocOverflowIndicator (indicator, action) {
      var $indicator = $(indicator);
      var opacity = action === 'show' ? 0.4 : 0;
      $indicator.velocity ?
        $indicator.velocity('stop').velocity({
          opacity: opacity
        }, { duration: 100 }) :
        $indicator.stop().animate({
          opacity: opacity
        }, 100);
    }

  });
</script>

<script type="text/javascript" id="sidebar.nav">
  $(document).ready(function () {
    var html = $('html');
    var TAB_ANIMATE_DURATION = 200;
    var hasVelocity = $.isFunction(html.velocity);

    $('.sidebar-nav li').on('click', function () {
      var item = $(this);
      var activeTabClassName = 'sidebar-nav-active';
      var activePanelClassName = 'sidebar-panel-active';
      if (item.hasClass(activeTabClassName)) {
        return;
      }

      var currentTarget = $('.' + activePanelClassName);
      var target = $('.' + item.data('target'));

      hasVelocity ?
        currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
          target
            .velocity('stop')
            .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
            .addClass(activePanelClassName);
        }) :
        currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
          currentTarget.hide();
          target
            .stop()
            .css({'opacity': 0, 'display': 'block'})
            .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
              currentTarget.removeClass(activePanelClassName);
              target.addClass(activePanelClassName);
            });
        });

      item.siblings().removeClass(activeTabClassName);
      item.addClass(activeTabClassName);
    });

    $('.post-toc a').on('click', function (e) {
      e.preventDefault();
      var targetSelector = escapeSelector(this.getAttribute('href'));
      var offset = $(targetSelector).offset().top;
      hasVelocity ?
        html.velocity('stop').velocity('scroll', {
          offset: offset  + 'px',
          mobileHA: false
        }) :
        $('html, body').stop().animate({
          scrollTop: offset
        }, 500);
    });

    // Expand sidebar on post detail page by default, when post has a toc.
    var $tocContent = $('.post-toc-content');
    if (isDesktop() && CONFIG.sidebar === 'post') {
      if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
        displaySidebar();
      }
    }
  });
</script>



  <script type="text/javascript">
    $(document).ready(function () {
      if (CONFIG.sidebar === 'always') {
        displaySidebar();
      }
      if (isMobile()) {
        FastClick.attach(document.body);
      }
    });
  </script>

  

  
  

  
  <script type="text/javascript" src="/js/lazyload.js"></script>
  <script type="text/javascript">
    $(function () {
      $("#posts").find('img').lazyload({
        placeholder: "/images/loading.gif",
        effect: "fadeIn"
      });
    });
  </script>

  <!-- google search, added by felix -->
  <script>
      $('#gg-form').on('submit', function(e) {
        var keyword = $.trim($(this).find('#gg-search-input').val());
        if (keyword) {
          location.href = 'https://www.google.com.hk/?gfe_rd=cr&ei=hXw8VpjtHuLC8AeSuIjQAg&gws_rd=ssl#safe=strict&q='+encodeURIComponent(keyword)+'+site:xgfe.github.io';
        }
        return false;
      });
  </script>
  <!-- baidu 站长自动推送 -->
  <script>
  (function(){
      var bp = document.createElement('script');
      bp.src = '//push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>
</body>
</html>
